<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //ES6允许使用箭头(=>)来定义函数
        let addFn = (a,b) => {
            return a+b;
        }
        console.log(addFn(2,3));

        //箭头函数的this是静态的
        window.name = '华为';
        const company = {
            name:"小米"
        }

        function getName(){
            console.log(this.Name);
        }

        let getName2 = () => {
            console.log(this.Name);
        }

        

        getName.call(company);
        getName2.call(company);

        //箭头函数不能作为构造函数来实例化对象
        // let Person = (name,age) => {
        //     this.name = name;
        //     this.age = age;
        // }
        // let me = new Person('ArimaMisaki',30);
        // console.log(me);

        //3 箭头函数不能使用arguments变量
        // let fn = () => {
        //     console.log(arguments);
        // }
        // fn(1,2,3);
        
        //4 箭头函数的简写
        //(1) 省略小括号，当形参有且只有一个
        let add = n => {
            return n+n;
        }
        console.log(add(9));
        //(2) 省略花括号，当代码体只有一条语句时
        let pow = n =>  n*n;
        console.log(pow(8));
    </script>
</body>
</html>